package leetcode.D100.T36;

/**
 * @Author: duyuzhou
 * @Create: 2022-04-16 21:23:09 星期六
 */

class Solution {
    public boolean isValidSudoku(char[][] board) {
        boolean[][] colTable = new boolean[9][9];
        boolean[][] rowTable = new boolean[9][9];
        boolean[][] boxTable = new boolean[9][9];
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (board[i][j] == '.')
                    continue;
                int k = board[i][j] - '1';
                int boxRow = i / 3, boxCol = j / 3;
                int boxId = boxRow * 3 + boxCol;
                if (rowTable[i][k] || colTable[j][k] || boxTable[boxId][k])
                    return false;
                rowTable[i][k] = true;
                colTable[j][k] = true;
                boxTable[boxId][k] = true;
            }
        }
        return true;
    }
}